<?php
$this->breadcrumbs=array(
	'Emails',
);

$this->menu=array(
	array('label'=>'Create Email', 'url'=>array('create')),
	array('label'=>'Manage Email', 'url'=>array('admin')),
);
?>

<script type="text/javascript">
<!--
$(function(){
	load();

	$(".portlet-title").click(function(){
		return false;
	});
});

function load(){

	var cgroup = $("#link_group").val();
	var cpage = $("#link_page").val();

	
	var url = '<?php echo $this->createUrl('lists',array('rn'=>time()));?>';
	url = url.replace(/<?php echo Yii::app()->urlManager->urlSuffix; ?>/,'/cgroup/'+cgroup+'/cpage/'+cpage+'<?php echo Yii::app()->urlManager->urlSuffix; ?>');

			
	$("#links-detail")
	 .css('background-color','yellow')
	.load(url)
    .css('background-color','white');
	
}

function updateItem(id){
	
	var url = '<?php echo $this->createUrl('iteminfo');?>';

	url = url.replace(/<?php echo Yii::app()->urlManager->urlSuffix;?>/,'/id/'+id+'<?php echo Yii::app()->urlManager->urlSuffix;?>');

//	alert(url);
//	$.get(url,function(msg){
//		alert(msg);
//	});
	
	$("#item-"+id).load(url);
}

function hoverOverShow(object){

	object.find(".quick").show();
}

function hoverOutHide(object){

	object.find(".quick").hide();
}

function actionShow(object){

	url = object.attr("id");
	
	$.colorbox({href:url,slideshow:true});

	return false;
}

function actionStatus(object){

	url = object.attr("id");


	$.post(url,function(data){
		if(data == 'ok'){
//			load();
			var id = object.parent().attr("gid");

			updateItem(id);
		
		}		
	});

}


function checkAll(object){
	$("input[name=link_item]").each(function(){
		if($(object).attr("checked") == true){
			$(this).attr("checked",true);
		}else{
			$(this).attr("checked",false);
		}
	});
}

function getSelectedInfo(){
    var str = '';
    $("input[name='link_item']").each(function(i){
        if($(this).attr('checked') == true){
            str += ','+$(this).val();
        }
        
    });
    
    //str = str.substr(1,str.length());
    str = str.substring(1);
    arr = str.split(',');
    return arr;
}

function actionBatch(object){
	 

    var ajax = 0;
    var arr = getSelectedInfo();

//    alert(arr);

    len = arr.length;       

   if(arr[0] != ''){
        if(object.val() == 'delete'){
           
            $.msgbox({
               height:100,
               width:250,
               content:{type:'confirm', content: '确认要删除选中的链接吗？'},
               animation:4,
               onClose:function(v){
                   if(v){
                       

                       for(i in arr){
                           if(i == (len-1)){
                               ajax = 1;
                           }
                           
                           
                           url = "<?php echo $this->createUrl('ajaxdelete'); ?>";
                           url = url.replace(/<?php echo Yii::app()->urlManager->urlSuffix;?>/,"/id/"+arr[i]+"<?php echo Yii::app()->urlManager->urlSuffix;?>");


                           $.post(url,{'ajax':ajax},function(data){
                               
                               if(data == 'ok'){
                                   $.msgbox({
                                      height:100,
                                      width:250,
                                      content:{type:'alert',content:'删除完毕！'},
                                      animation:4 
                                   });                                        
                               }   
                                
                               $("#link_item"+arr[i]).parent().css({'background':'yellow'}).fadeOut();
                               
                               load();                 

                               
                           });
                           
                       }                  
                   }
               }
            });           
       }      
        
   }else{
       $.msgbox({
           'height':100,
           'width':250,
           'animation':4,
           content:{type:'alert',animate:4,content:'请选择要操作的链接！'}
       });
   }         
}



//-->
</script>

<div id="detail-info" class="column1" style="width:100%;">
<?php 
	$html = '<input type="checkbox" name="checkAll" onclick="checkAll($(this),\'comment-item\');" value="'.$data->com_id.'" />'.Yii::t('common','Check All').'&nbsp;&nbsp;&nbsp;&nbsp;'.Yii::t('comment' ,'Comment State').'：&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="actionCommentsBatch();" value="'.Yii::t('admin','Submit').'" />';
?>
<?php 
$cgroup = CHtml::dropDownList('link_group','',UArray::arrayMerge(array(''=>Yii::t('user', 'Group'),),User::model()->getUserGroupArray()),array('onchange'=>'load();'));


$html = <<<DOC
   <span>
    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    	{$cgroup}
    	&nbsp;&nbsp;
    	<select name="link_page" id="link_page" onchange="load();">
    		<option value="">每页显示条数</option>
    		<option value="5">5</option>
    		<option value="10">10</option>
    		<option value="15">15</option>
    		<option value="20">20</option>
    	</select>
    	&nbsp;&nbsp;
    	<select name="link_action" onchange="actionBatch($(this));">
    		<option value="">选择操作</option>
    		<option value="delete">删除</option>
    		<option value="trash">回收站</option>
    	</select>
    	
    </span>
DOC;
?>
	<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>CHtml::image($this->module->registerImage('article.png'),'Logo', array('width'=>'20'),array('htmlOptions'=>'class="dd"')).'&nbsp;&nbsp;链接列表'.$html,	));?>
	<div class="box">		
		<div class="box-title" style="height:30px;padding-top:5px;margin-top:5px;">
			<div class="left" style="margin-left:25px;width:30px;">
    	
    	<input type="checkbox" name="link_check" onclick="checkAll($(this))" />
    	</div>
			<div class="left" style="width:20%;">邮件主题</div>
			<div class="left" style="width:15%;">发件人</div>
			<div class="left" style="width:50%;text-align:center;">邮件内容</div>
		</div>
		<div class="box-content">
			<div id="links-detail">
			
			</div>			
		</div>		
	</div>
	<?php $this->endWidget();?>
</div>

<?php $this->widget('ext.box.colorbox.colorboxWidget',array(
		'id'=>'.link-item-name',
		'theme'=>'example1',
//		'options'=>'width:"50%", inline:true, href:"#uploadbox",onClosed:function(){ load(); }'
));?> 